package com.ruoyi.pay.controller;

import com.ruoyi.pay.utils.QRCodeUtil;
import com.ruoyi.pay.utils.WxPayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @author : XiXi
 * @date : 2024-10-25 20:42
 * @description :
 **/
@RestController
@RequestMapping("/wxpayExam")
@CrossOrigin    // 跨域
public class WxpayExamController {

    @Autowired
    WxPayUtils wxPayUtils;

    /**
    * //TODO 微信支付
    * @Author: XiXi
    * @Description:
    * @Param: [orderId, response]
    * @return: void
    * @Date: 2024/10/25 下午 8:48
    */
    @GetMapping("/pay/{orderId}")
    public void pay(@PathVariable("orderId") String orderId,HttpServletResponse response){

        String codeUrl = wxPayUtils.wxPay(orderId);
        System.out.println(codeUrl);
        QRCodeUtil.createQRCode(response,codeUrl);


//        String codeUrl = wxPayUtils.wxPay(orderId);
//        System.out.println(codeUrl);
//        //将二维码的字符串转成图片，返回浏览器
//        QRCodeUtil.createQRCode(response,codeUrl);

    }

    @GetMapping("/query/{orderId}")
    public Boolean query(@PathVariable("orderId") String orderId) throws Exception {
        Boolean result = wxPayUtils.refreshWxPay(orderId);
        if (result == true){
            //TODO 根据订单编号修改订单状态

        }

        return result;
    }

}
